<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
<!--    <script src="./lib/axios.min.js"></script>-->
    <script src="./lib/zhang.js"></script>
</head>
<body>
    <button>发送请求</button>
    <button>取消请求</button>
</body>
<script>
    const btns = document.querySelectorAll("button");
	let cancelHandler = null;
	btns[0].onclick = function(){
		// axios({
        //     url:"http://zhangpeiyue.com/scorelist"
        // }).then(value=>{
		// 	console.log(value);
        // })

		axios.get("http://zhangpeiyue.com/scoreList",{
			// cancelToken是一个对象：{cancel:promise实例（状态为初始值pending）}
            cancelToken:new axios.CancelToken(function(cancel){
				cancelHandler = cancel;
            })
        }).then(value=>{
			console.log(value.data)
        }).catch(err=>{
			console.log(err);
        })
    }
	btns[1].onclick = function(){
		if(cancelHandler) cancelHandler();
    }
</script>
</html>